package com.example.demo.controller;

import com.example.demo.entity.Aunt;
import com.example.demo.entity.CanteenMan;
import com.example.demo.enums.ResultEnum;
import com.example.demo.service.GilService;
import com.example.demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/gil")
public class GilController {
    @Autowired
    private GilService gilService;

    @RequestMapping("/findCanteenManTotal")
    public ResultVO findCanteenManTotal(){
       int result = gilService.findCanteenManTotal();
       return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/findAuntTotal")
    public ResultVO findAuntTotal(){
       int result = gilService.findAuntTotal();
       return new ResultVO(ResultEnum.SUCCESS,result);
    }

    @RequestMapping("/findCanteenMansByPage")
    public ResultVO findCanteenMansByPage(String startNum,String size){
        List<CanteenMan> lists = gilService.findCanteenMansByPage(Integer.valueOf(startNum),Integer.valueOf(size));
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }
    @RequestMapping("/findAuntByPage")
    public ResultVO findAuntByPage(String startNum,String size){
        List<Aunt> lists = gilService.findAuntByPage(Integer.valueOf(startNum),Integer.valueOf(size));
        return new ResultVO(ResultEnum.SUCCESS,lists);
    }

    @RequestMapping("/updateCanteenMan")
    public ResultVO updateCanteenMan(@RequestParam Map<String,String> map){
        int result = gilService.updateCanteenMan(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/updateAunt")
    public ResultVO updateAunt(@RequestParam Map<String,String> map){
        int result = gilService.updateAunt(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/addCanteenMan")
    public ResultVO addCanteenMan(@RequestParam Map<String,String> map){
        int result = gilService.addCanteenMan(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/addAunt")
    public ResultVO addAunt(@RequestParam Map<String,String> map){
        int result = gilService.addAunt(map);
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/delCanteenMan")
    public ResultVO delCanteenMan(String cid){
        int result = gilService.delCanteenMan(Integer.valueOf(cid));
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
    @RequestMapping("/delAunt")
    public ResultVO delAunt(String aid){
        int result = gilService.delAunt(Integer.valueOf(aid));
        return new ResultVO(ResultEnum.SUCCESS,result);
    }
}
